home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / tab100 / tab.bas < prev    next >
BASIC Source File  |  1995-09-06  |  21KB  |  795 lines

  1.  
  2. Sub TestForJack (Pv As Integer, Vp As String, Flag As Integer)
  3.         If Pv = 12 Then
  4.            Vp = "Y"
  5.         End If
  6. End Sub
  7.  
  8. Sub TestEqualRank (Pv As Integer, Vp As String, RCds As Integer)
  9.     Dim i As Integer
  10.  
  11.     For i = 1 To TableNo
  12.         If Pv = TableArray(i) Then
  13.             Vp = "Y"
  14.             NewTableArray(i) = 0
  15.             RCds = RCds - 1
  16.         End If
  17.     Next i
  18.     
  19. End Sub
  20.  
  21. Sub TestEqualValue (Pv As Integer, Vp As String, RCds As Integer)
  22.     
  23.     Dim MatchFound As Integer
  24.     Dim j As Integer
  25.     Dim k As Integer
  26.     
  27.     For j = 1 To TableNo - 1
  28.         For k = j + 1 To TableNo
  29.             If Pv = TableArray(j) + TableArray(k) Then
  30.                 Vp = "Y"
  31.                 NewTableArray(j) = 0
  32.                 NewTableArray(k) = 0
  33.                 RCds = RCds - 2
  34.                 Exit Sub
  35.             End If
  36.             TestAsAces TableArray(j), TableArray(k), Pv, RCds, Vp, MatchFound
  37.             If MatchFound = TRUE Then
  38.                 NewTableArray(j) = 0
  39.                 NewTableArray(k) = 0
  40.                 RCds = RCds - 2
  41.                 Exit Sub
  42.             End If
  43.         Next k
  44.     Next j
  45.     
  46. End Sub
  47.  
  48. Sub TestForTypeOfPlay (Pv As Integer, Vp As String, Pos As Integer, RCds As Integer, TyOP As Integer)
  49.         
  50.     Dim i As Integer
  51.     Dim SumRCds As Integer
  52.  
  53.     SumRCds = 0
  54.  
  55.     If Pv = 12 Then
  56.         TyOP = JACK
  57.         Exit Sub
  58.     End If
  59.  
  60.     If RCds = 0 Then
  61.         TyOP = TABLENETTE
  62.         Exit Sub
  63.     End If
  64.  
  65.     For i = 1 To TableNo
  66.         SumRCds = SumRCds + NewTableArray(i)
  67.     Next i
  68.  
  69.     If SumRCds = 12 Then
  70.         TyOP = TOTAL_12
  71.         Exit Sub
  72.     End If
  73.  
  74.     If RCds = 1 Then
  75.         If SumRCds > 11 Then
  76.             SumRCds = SumRCds - 1
  77.         End If
  78.         If SumRCds = 11 Then
  79.             SumRCds = 1
  80.         End If
  81.         Select Case EqualRankGone(SumRCds)
  82.             Case 3
  83.                 TyOP = ONECARD_NOEQUAL
  84.             Case 2
  85.                 TyOP = ONECARD_ONEEQUAL
  86.             Case 1, 0
  87.                 Vp = ""
  88.                 TyOP = REJECTED_MOVE
  89.         End Select
  90.         Exit Sub
  91.     End If
  92.             
  93.  
  94.     If RCds >= 3 Then
  95.         TyOP = THREECARDS_PLUS
  96.     Else
  97.         TyOP = TWOCARDS
  98.     End If
  99.             
  100. End Sub
  101.  
  102. Sub AddToCardsTotal (Count As Integer)
  103.     If GameSwitch = PLAYER_MOVE Then
  104.         PlayerCardsNo = PlayerCardsNo + Count
  105.     Else
  106.         ComputerCardsNo = ComputerCardsNo + Count
  107.     End If
  108. End Sub
  109.  
  110. Sub AddToEqualRank (C1 As Integer)
  111.     EqualRankGone(C1) = EqualRankGone(C1) + 1
  112. End Sub
  113.  
  114. Sub AddToScore (C1 As Integer)
  115.  
  116.     Dim Score As Integer
  117.     If GameSwitch = PLAYERMOVE Then
  118.         Score = PSCore
  119.         PickUpSwitch = PLAYER
  120.     Else
  121.         Score = CSCore
  122.         PickUpSwitch = COMPUTER
  123.     End If
  124.  
  125.     Select Case C1
  126.         Case 1, 14, 27, 40          'Aces count 1
  127.             Score = Score + 1
  128.         Case 13, 26, 39, 52         'Kings count 1
  129.             Score = Score + 1
  130.         Case 12, 25, 38, 51         'Queens count 1
  131.             Score = Score + 1
  132.         Case 11, 24, 37, 50         'Jacks count 1
  133.             Score = Score + 1
  134.         Case 10, 23, 36             '10s except Diamonds score 1
  135.             Score = Score + 1
  136.         Case 49                     '10 Diamonds scores 2
  137.             Score = Score + 2
  138.         Case 28                     '2 Clubs scores 1
  139.             Score = Score + 1
  140.     End Select
  141.  
  142.     If GameSwitch = PLAYER_MOVE Then
  143.         PSCore = Score
  144.         If Val(Form1.PlayerScore.Caption) <> PSCore Then
  145.             Form1.PlayerScore.Caption = Str$(PSCore)
  146.         End If
  147.     Else
  148.         CSCore = Score
  149.         If Val(Form1.ComputerScore.Caption) <> CSCore Then
  150.             Form1.ComputerScore.Caption = Str$(CSCore)
  151.         End If
  152.     End If
  153.  
  154. End Sub
  155.  
  156. Sub AskForNewGame ()
  157.  
  158.     Dim MsgBoxResponse As Integer
  159.  
  160.     MsgBoxResponse = MsgBox("Do You Wish to Play Again", MBB_YNCAN + MBI_INFO)
  161.     If MsgBoxResponse = MB_YES Then
  162.         NewGame
  163.         FirstDeal
  164.     Else
  165.         End
  166.     End If
  167. End Sub
  168.  
  169. Function BestComputerDiscard ()
  170.     
  171.     Dim i As Integer
  172.     
  173.  
  174.     If TableNo = 0 Then
  175.         DiscardOnZero
  176.     Else
  177.         If TableNo > 0 Then
  178.             DiscardOnOne
  179.         End If
  180.     End If
  181.     
  182.     For i = 1 To 10
  183.         For j = 1 To ComputerNo
  184.                 If TypeOfDiscard(j) = i Then
  185.                     BestComputerDiscard = j
  186.                     Exit Function
  187.                 End If
  188.         Next j
  189.     Next i
  190.     
  191.  
  192. End Function
  193.  
  194. Function BestComputerMove ()
  195.     Dim i As Integer
  196.     Dim j As Integer
  197.  
  198.     Flag = False
  199.     
  200.     For i = 1 To 7
  201.         For j = 1 To ComputerNo
  202.             If ValidPlay(j) = "Y" Then
  203.                 If TypeOfPlay(j) = i Then
  204.                     BestComputerMove = j
  205.                     Flag = True
  206.                     Exit Function
  207.                 End If
  208.             End If
  209.         Next j
  210.     Next i
  211.  
  212. End Function
  213.  
  214. Sub CheckFor27Cards ()
  215.     If PlayerCardsNo > 27 Then
  216.         PSCore = PSCore + 3
  217.         Form1.PlayerScore.Caption = Str$(PSCore)
  218.     End If
  219.     If ComputerCardsNo > 27 Then
  220.         CSCore = CSCore + 3
  221.         Form1.ComputerScore.Caption = Str$(CSCore)
  222.     End If
  223. End Sub
  224.  
  225. Function CheckForWin ()
  226.     
  227.     Flag = False
  228.  
  229.     If Val(Form1.PlayerScore.Caption) > 251 Then
  230.         If Val(Form1.PlayerScore.Caption) > Val(Form1.ComputerScore.Caption) Then
  231.             MsgBox ("Well done you've Won")
  232.             CheckForWin = True
  233.         Else
  234.             MsgBox ("Computer Wins This Game")
  235.             Flag = True
  236.         End If
  237.     Else
  238.         If Val(Form1.ComputerScore.Caption) > 251 Then
  239.             MsgBox ("Computer Wins This Game")
  240.             CheckForWin = True
  241.         End If
  242.     End If
  243.  
  244. End Function
  245.  
  246. Sub CheckTableCards (A() As String, V As Integer, Pos As Integer, VNo As Integer)
  247.  
  248.  
  249.     Dim TableVal As Integer
  250.     Dim FirstCardVal As Integer
  251.     Dim j As Integer
  252.     
  253.  
  254.     TableVal = CardValue(Cards(Val(Form1.Picture1(Pos).Tag)))
  255.     SetNewValue TableVal
  256.     FirstCardVal = TableVal
  257.     
  258.  
  259.  
  260.     For j = Pos + 1 To TableNo
  261.         TableVal = CardValue(Cards(Val(Form1.Picture1(j).Tag)))
  262.         SetNewValue TableVal
  263.         If V = FirstCardVal + TableVal Then
  264.             A(VNo + 1) = Str$(Pos) + "," + Str$(j)
  265.             VNo = VNo + 1
  266.         Else
  267.             CheckAcesAsOne FirstCardVal, TableVal, V, A(), Pos, j, VNo
  268.         End If
  269.     Next j
  270.     
  271. End Sub
  272.  
  273. Sub ClearValidPlays ()
  274.     For i = 1 To 6
  275.         ValidPlay(i) = ""
  276.         TypeOfPlay(i) = 0
  277.     Next i
  278. End Sub
  279.  
  280. Sub DiscardOnOne ()
  281.     
  282.     Dim CompCard As Integer
  283.     Dim TableCard As Integer
  284.     Dim TwoCardVal  As Integer
  285.  
  286.     TableCard = CardValue(Cards(Val(Form1.Picture1(1).Tag)))
  287.     SetNewValue TableCard
  288.     
  289.  
  290.     For i = 1 To ComputerNo
  291.         CompCard = CardValue(Cards(Val(Form1.Picture4(i).Tag)))
  292.         SetNewValue CompCard
  293.  
  294.         If CompCard = TableCard Then
  295.             TypeOfDiscard(i) = 10
  296.         Else
  297.             If CompCard + TableTotal = 12 Then
  298.                 If CompCard <> TableCard Then
  299.                     TypeOfDiscard(i) = 1
  300.                 End If
  301.             Else
  302.                 If CompCard + TableTotal > 14 Then
  303.                     If CompCard <> TableCard Then
  304.                         TypeOfDiscard(i) = 2
  305.                     End If
  306.                 Else
  307.                     Select Case EqualRankGone(CardValue(Cards(Val(Form1.Picture4(i).Tag))))
  308.                         Case 3
  309.                             TypeOfDiscard(i) = 3
  310.                         Case 2
  311.                             If CardValue(Cards(Val(Form1.Picture4(i).Tag))) < 7 Then
  312.                                 TypeOfDiscard(i) = 4
  313.                             Else
  314.                                 TypeOfDiscard(i) = 5
  315.                             End If
  316.                         Case 1
  317.                             If CardValue(Cards(Val(Form1.Picture4(i).Tag))) < 7 Then
  318.                                 TypeOfDiscard(i) = 6
  319.                             Else
  320.